package edu.umassd.hciproject;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/*
 * As suggested by Vivek Parihar at
 *  http://stackoverflow.com/questions/4238921/android-detect-whether-there-is-an-internet-connection-available
 */
public class AppStatus {
	private static AppStatus instance = new AppStatus();
    static Context context;
    boolean connected = false;

    public static AppStatus getInstance(Context ctx) {
        context = ctx;
        return instance;
    }
    

    // Note: This method requires ACCESS_NETWORK_STATE permission 
    public boolean isOnline() {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();        
        connected = (networkInfo != null) && networkInfo.isAvailable() && networkInfo.isConnected();
        
        return connected;
    }

}
